require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                userInfo: {},
                money: "",
                thatUser: "",
            }
            , created: function () {
                this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    var tool = [];
                    toolbar.push({
                        "clas": "",
                        "eve": "PAY",
                        "tit": "付款",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            data[0]['status'] = "YES";
                            var re = playPut("v1/api/shopOrder/status/" + data[0]['id'],
                                "", "YES");
                            alr(re.msg);
                            setTimeout(function () {
                                window.reload();
                            }, 500);
                            return false;
                        }
                    });
                    toolbar.push({
                        "clas": "",
                        "eve": "MAIL",
                        "tit": "邮寄",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            data[0]['status'] = "MAIL";
                            var re = playPut("v1/api/shopOrder/status/" + data[0]['id'],
                                "", "MAIL");
                            alr(re.msg);
                            setTimeout(function () {
                                window.reload();
                            }, 500);
                            return false;
                        }
                    });
                    toolbar.push({
                        "clas": "",
                        "eve": "CALL",
                        "tit": "取消",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            data[0]['status'] = "CALL";
                            var re = playPut("v1/api/shopOrder/status/" + data[0]['id'],
                                "", "CALL");
                            alr(re.msg);
                            setTimeout(function () {
                                window.reload();
                            }, 500);
                            return false;
                        }
                    });
                    bspVIEW($("#authoritiesTable"), "/v1/api/shopOrder/all", [
                        {type: 'radio',width: 150},
                        {type: 'numbers'},
                        {field: 'id', title: '订单id', minWidth: 50, width: 120},
                        {
                            templet: function (d) {
                                return d.users.name;
                            },
                            align: 'center',
                            width: 120,
                            title: '用户名称'
                            , minWidth: 120
                        },
                        {field: 'count', title: '商品数量', minWidth: 50, width: 120},
                        {field: 'incomeMoney', title: '应收金额', minWidth: 50, width: 120},
                        {field: 'money', title: '实收金额', minWidth: 50, width: 120},
                        {field: 'annul', title: '抵扣金额', minWidth: 50, width: 120},
                        {field: 'createTime', title: '下单时间', minWidth: 50, width: 100},
                        {
                            templet: function (d) {
                                return d.userSite.site;
                            },
                            align: 'center',
                            width: 120,
                            title: '收货地址'
                            , minWidth: 120
                        },
                        {
                            templet: function (d) {
                                if(d.userSite.pick){
                                    return "自提"
                                }else{
                                    return "非自提"
                                }
                            },
                            align: 'center',
                            width: 120,
                            title: '是否自提'
                            , minWidth: 120
                        },
                        {
                            templet: function (d) {
                                return d.userSite.people;
                            },
                            align: 'center',
                            width: 120,
                            title: '收货人'
                            , minWidth: 120
                        },
                        {
                            templet: function (d) {
                                return d.userSite.mobile;
                            },
                            align: 'center',
                            width: 120,
                            title: '电话'
                            , minWidth: 120
                        },
                        {
                            templet: function (d) {
                                if (d.status.number == 0) {
                                    return "<p style='background-color: darkorange;color: black'>待确认</p>";
                                }
                                if (d.status.number == 1) {
                                    return "<p style='background-color: yellow;color: black'>未付款</p>";
                                }
                                if (d.status.number == 2) {
                                    return "<p style='background-color:green;color: white'>已付款</p>";
                                }
                                if (d.status.number == 5) {
                                    return "<p style='background-color:red;color: white'>取消</p>";
                                }
                                if (d.status.number == 3) {
                                    return "<p style='background-color:blue;color: white'>邮寄中</p>";
                                }
                                if (d.status.number == 4) {
                                    return "<p>已收货</p>";
                                }
                            },
                            align: 'center',
                            width: 120,
                            title: '订单状态'
                            , minWidth: 120
                        }
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                }
            }
        });
    })
});